package com.bd;

import java.util.List;

import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;

public class DataSource {
   
    private SQLiteDatabase database;
    private MySQLiteHelper dbHelper;
   
    public DataSource(Context context){
        this.dbHelper = new MySQLiteHelper(context);
    }
   
    public void open() throws SQLException {
        this.database = this.dbHelper.getWritableDatabase();
    }
   
    public void close() {
        this.dbHelper.close();
    }    
   
    /***************************************************************************
     * PetsModule
     **************************************************************************/
    public PetsModule createPet(PetsModule pet){
        PetsModule module_inserted = pet.insertPet(this.database);
        return module_inserted;
    }
   
    public void deletePet(PetsModule module){
        module.deletePet(this.database);
    }
   
    public boolean updatePet(PetsModule module){
        boolean updated = module.updatePet(this.database);
        return updated;
    }
   
    public PetsModule getPet(String module_id){
       
        PetsModule module_selected;
        module_selected = PetsModule.getPet(this.database, module_id);
       
        return module_selected;
    }
   
    public List<PetsModule> getAllPets(){
        return PetsModule.getAllPets(database);
    }
   
    /***************************************************************************
     * PetsModule
     **************************************************************************/
    public AlarmsModule createAlarm(AlarmsModule alarm){
        AlarmsModule module_inserted = alarm.insertAlarm(this.database);
        return module_inserted;
    }
   
    public void deleteAlarm(AlarmsModule module){
        module.deleteAlarm(this.database);
    }
   
    public boolean updateAlarm(AlarmsModule module){
        boolean updated = module.updateAlarm(this.database);
        return updated;
    }
   
    public AlarmsModule getAlarm(String module_id){
       
        AlarmsModule module_selected;
        module_selected = AlarmsModule.getAlarm(this.database, module_id);
       
        return module_selected;
    }
   
    public List<AlarmsModule> getAllAlarms(){
        return AlarmsModule.getAllAlarms(this.database);
    }
    
    public List<AlarmsModule> getAllAlarmsFromPet(String petid){
    	return AlarmsModule.getAllAlarmsFromPet(this.database, petid);
    }
    
    public List<AlarmsModule> getAllAlarmsFromPet(PetsModule pet){
    	return AlarmsModule.getAllAlarmsFromPet(this.database, pet.getPk()+"");
    }
    
    /***************************************************************************
     * VetsModule
     **************************************************************************/
    public VetsModule createVet(VetsModule vet){
        VetsModule module_inserted = vet.insertVet(this.database);
        return module_inserted;
    }
   
    public void deleteVet(VetsModule module){
        module.deleteVet(this.database);
    }
   
    public boolean updateVet(VetsModule module){
        boolean updated = module.updateVet(this.database);
        return updated;
    }
   
    public VetsModule getVet(String module_id){
       
        VetsModule module_selected;
        module_selected = VetsModule.getVet(this.database, module_id);
       
        return module_selected;
    }
   
    public List<VetsModule> getAllVets(){
        return VetsModule.getAllVets(this.database);
    }
    
}
